package com.example.dao;

import com.example.entity.StudentInfo;
import com.example.entity.TeacherInfo;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

/**
 * @author 涛某
 * @version 1.0
 * @date 2024/3/21 13:55
 */
@Repository
public interface StudentInfoDao extends Mapper<StudentInfo> {
    @Select("select * from student where name = #{name} and password = #{password}" )
    StudentInfo findByNameAndPassowrd(@Param("name") String name, @Param("password") String password);


    @Select("select * from student where id = #{id}")
    StudentInfo FindById(Long id);


    @Update("update student set name = #{name},sex=#{sex},age = #{age},  score= #{score},code= #{code} where id = #{id}")
    void update(StudentInfo studentInfo);

    @Insert("insert into student(name,sex,age,score,code,password) values(#{name},#{sex},#{age},#{score},#{code},#{password})")
    void add(StudentInfo studentInfo);

    @Select("select * from student where name = #{name}")
    StudentInfo FindByName(@Param("name") String name);


    @Select("select s.name,s.sex,s.age,s.score,s.code,x.name xueyuanid from student s left join xueyuan x on s.xueyuanid=x.id")
    List<StudentInfo> findAll();

    @Delete("delete from student where id = #{id}")
    void deleteById(Long id);

    @Select("select * from student where name like concat('%',#{name},'%')")
    List<StudentInfo> findByNamePage(@Param("name") String name);

    @Select("select a.*,b.name as xueyuanname from student as a left join xueyuan as b on a.xueyuanid=b.id")
    List<StudentInfo> findAllJoinxueyuan();
}
